package com.topgay.dao;

import java.util.HashMap;
import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.topgay.domain.CSCenter;
import com.topgay.util.BoardUtilities;

@Repository
public class CSCenterDAOImple implements CSCenterDAO{

	@Autowired
	private SqlSessionTemplate session;
	
	@Override
	public List<CSCenter> selectCSCenterList(int page, int divide) {
		HashMap map = new HashMap();
		map.put("contentPerPage", BoardUtilities.CONTENT_PER_PAGE);
		map.put("page", page);
		map.put("divide", divide);
		return session.selectList(makeSqlId("selectCSCenterList"), map);
	}
	
	@Override
	public int selectTotalContent(int divide){
		return session.selectOne(makeSqlId("selectTotalContent"), divide);
	}

	@Override
	public int insertCSCenterContent(CSCenter cscenter, int divide) {
		return session.insert(makeSqlId("insertCSCenterContent"), divide);
	}
	
	@Override
	public int selectMaxCSCenterDivideNo(int divide) {
		return session.selectOne(makeSqlId("selectMaxCSCenterDivideNo"), divide);
	}

	@Override
	public int updateCSCenterViewCount(int cscenterNo) {
		return session.update(makeSqlId("updateCSCenterViewCount"), cscenterNo);
	}

	@Override
	public CSCenter selectCSCenterContentByNo(int cscenterNo) {
		return session.selectOne(makeSqlId("selectCSCenterContentByNo"), cscenterNo);
	}

	private String makeSqlId(String id){
		return "cscenter." + id;
	}
	
}
